package com.fgi.springframework.beans.factory.support;

import com.fgi.springframework.beans.BeansException;
import com.fgi.springframework.beans.factory.config.BeanDefinition;

/**
 * @author HanXu
 * @date 2022/11/18
 **/
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    // TODO 实现 AbstractBeanFactory 中定义的 创建对象的抽象方法
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();

        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }

        addSingleton(beanName, bean);
        return bean;
    }

}

